#pragma once
#include <Rz/Object.h>
#include <Rz/Graphics/Render/IViewer.h>
#include <Rz/Graphics/Render/ViewerEvents.h>

static LRESULT CALLBACK __GLWin32Viewer_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

namespace Rz { namespace Graphics { namespace Render { namespace Libraries { namespace OpenGL {

class GLWin32Viewer :
	public Object,
	public IViewer
{
	friend LRESULT CALLBACK ::__GLWin32Viewer_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

	public:
		RZ_RTTI(Rz::Graphics::Render::Libraries::OpenGL, GLWin32Viewer);
		RZ_RTTI_IMPLEMENTS(Object, IViewer);
		RZ_RTTI_END;

		virtual bool Init(const ViewerState& state) override;
		virtual void End() override;
		virtual void Run() override;

	private:
		struct Win32Window
		{
			HINSTANCE	hInstance;
			HWND		hWnd;
			HDC			hDC;
			HGLRC		hRC;
		};

		LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
		bool ProcessMessage(bool* runFlag);
		void ProcessMouseInput();
		void ProcessKeyboardInput();
		void DrawTime(f32 elapsedTime, f32 frameTime);

		u32 _startTime, _frameTime;
		bool _active;

		Win32Window	_wnd;
};

} } } } }
